package com.hdcx.Minfresh.adapter;


import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdcx.Minfresh.R;
import com.hdcx.Minfresh.activity.BaseActivity;
import com.hdcx.Minfresh.bean.OrderDetailWrapper;
import com.hdcx.Minfresh.util.AppUtil;

/**
 * Created by Administrator on 2016/11/9.
 */

public class PointChangeOrderListAdapter extends RecyclerView.Adapter<PointChangeOrderListAdapter.Holder> {
    BaseActivity mActivity;
    OrderDetailWrapper data;


    public PointChangeOrderListAdapter(BaseActivity mActivity) {
        this.mActivity = mActivity;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater layoutInflater = LayoutInflater.from(mActivity);
        view = layoutInflater.inflate(R.layout.item_fragment_detail_more, parent, false);
        return new Holder(view);
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        OrderDetailWrapper.LIST itemtemp = data.getList().get(position);
        AppUtil.showPic(itemtemp.getPic(), holder.img_main);
        holder.tv_name.setText(itemtemp.getTitle());
        holder.tv_intro.setText(itemtemp.getShort_title());
        holder.tv_intro2.setText("规格：" + itemtemp.getEtalon() +"/"+ itemtemp.getUnits());
        holder.tv_units.setText("1" + itemtemp.getUnits());
        holder.tv_money.setText(itemtemp.getScore() + "分/" + itemtemp.getUnits());
        holder.layout_money.setVisibility(View.VISIBLE);
        holder.layout_no.setVisibility(View.VISIBLE);
        String temp = itemtemp.getScore()+"分";
        SpannableString styledText = new SpannableString(temp);
        styledText.setSpan(new TextAppearanceSpan(mActivity, R.style.tv_red), 0, temp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.tv_totle_money.setText(styledText, TextView.BufferType.SPANNABLE);
        holder.tv_no.setText("订单号：" + itemtemp.getOrder_sn());
        holder.tv_go.setText(itemtemp.getAdd_time());
        holder.tv_go.setTextColor(mActivity.getResources().getColor(R.color.line5));

    }

    @Override
    public int getItemCount() {
        if (data == null || data.getList()==null) {
            return 0;
        } else {
            return data.getList().size();
        }
    }

    @Override
    public int getItemViewType(int position) {
        return position;

    }

    public void setData(OrderDetailWrapper response) {
        data = response;
        notifyDataSetChanged();
    }

    public class Holder extends RecyclerView.ViewHolder {
        public LinearLayout layout_no, layout_money , layout_all;
        public TextView tv_totle_money, tv_intro, tv_intro2, tv_name, tv_units, tv_no, tv_money,tv_status,tv_go;
        public ImageView img_main;

        public Holder(View itemView) {
            super(itemView);
            layout_no = (LinearLayout) itemView.findViewById(R.id.layout_no);
            layout_money = (LinearLayout) itemView.findViewById(R.id.layout_money);
            layout_all = (LinearLayout) itemView.findViewById(R.id.layout_all);
            tv_totle_money = (TextView) itemView.findViewById(R.id.tv_totle_money);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_intro = (TextView) itemView.findViewById(R.id.tv_intro);
            tv_intro2 = (TextView) itemView.findViewById(R.id.tv_intro_2);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_units = (TextView) itemView.findViewById(R.id.tv_units);
            tv_no = (TextView) itemView.findViewById(R.id.tv_no);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
            tv_go = (TextView) itemView.findViewById(R.id.tv_go);
            img_main = (ImageView) itemView.findViewById(R.id.img_main);

        }
    }
}
